﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Arizu.Repository;
using System.Data;
using Arizu.Entity;

namespace AiRiZu.User
{
    public partial class DoRegist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LogButton_Click(object sender, EventArgs e)
        {
            AirizuUser user = AirizuUser.CreateInstance();
            DataTable dt = user.GetUserByEmail(this.emailLogin.Text);

            if (dt.Rows.Count > 0)
            {
                if (this.passwordLogin.Text.Equals(dt.Rows[0]["Pass"].ToString(), StringComparison.Ordinal))
                {
                    //Message.Alert("OK");
                    Session["logId"] = dt.Rows[0]["PersonId"].ToString();
                    Session["aliance"] = dt.Rows[0]["Xing"].ToString() + " " + dt.Rows[0]["Ming"].ToString();
                    Response.Redirect("dashboard.aspx", true);
                }
                else
                {
                    //Message.Alert("Error pwd");
                }
            }
            else
            {
                //Message.Alert("Error user id");
            }
        }

        protected void RegistButton_Click(object sender, EventArgs e)
        {
            AirizuUser user = AirizuUser.CreateInstance();

            UserEntity userEntity = new UserEntity();
            userEntity.Email = this.emailRegist.Text;
            userEntity.Pass = this.passwordRegist.Text;
            userEntity.Xing = this.firstNameRegist.Text;
            userEntity.Ming = this.lastNameRegist.Text;
            userEntity.MobileTelephone = this.phoneNumberRegist.Text;
            user.InsertUserInfo(userEntity);

            DataTable dt = user.GetUserByEmail(userEntity.Email);
            if (dt.Rows.Count > 0)
            {
                Session["logId"] = dt.Rows[0]["PersonId"];
                Session["aliance"] = dt.Rows[0]["Xing"].ToString() + " " + dt.Rows[0]["Ming"].ToString();
            }
            Response.Redirect("DashBoard.aspx", true);
        }
    }
}
